145 replace css class locators in e2e tests with role based locators #153
+524
−1,580
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Makes the E2E tests find elements the way a user or screen reader would, replaces the full-page snapshots, and adds an E2E test for the core feature of the app. The new test found a bug, which is fixed here too.
E2E locators
getByRole,getByLabelandtoHaveAccessibleNamee2e/helpers/names.ts, so the tests work in Norwegian and EnglishgoToPage(navigation through the sidebar) ande2e/helpers/locators.ts(shared locators for plant cards)data-testidadded where there is no natural role: plant cards in lists, the placeholder image and the avatar buttonsuiAccessibilitystill uses CSS selectors on purpose, since it checks contrast and axe rules on specific elementsSnapshots
FilterSelectwith counts and a disabled value. LanguageSwitcher snapshots kept. Snapshots are now only used for small components that seldom changeNew E2E test:
uiPreferencesA new user lands on Plant Match, chooses preferences on the profile and goes back. The first card must match all preferences, also after a reload and after changing the preferences. The test data has only one or two plants matching each set, so the expected plants are known.
Bug fix: Plant Match kept the old order
The deck in
sessionStoragewas only restarted when the preferences changed while Plant Match was open. Since preferences are changed on the profile page, users always got the old order, including every new user choosing preferences for the first time. The saved deck now remembers which preferences it was sorted by, and starts over if they no longer match. Covered by new component tests inPlantMatchPage.test.tsx.Documentation
docs/tests.md: why the tests use roles and names, when snapshots are used, the new E2E test and the fix.